<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.el.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.config.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.chart.*"%>
<%@ page import="com.gzgi.framework.entity.*"%>
<%@ page import="com.gzgi.framework.dataitem.*"%>
<%@ page import="com.gzgi.framework.integration.*"%>
<%@ page import="com.gzgi.framework.sys.*"%>
<%@ page import="com.gzgi.framework.sys.model.*"%>
<%@ page import="com.gzgi.framework.sys.util.*"%>
<%@ page import="com.gzgi.crm.context.*"%>
<%@ page import="com.gzgi.crm.report.*"%>
<%@ page import="com.gzgi.crm.service.*"%>
<%@ page import="com.gzgi.crm.model.*"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%

		  SalesContext ctx = new SalesContext();

		  Calendar calendar = new GregorianCalendar();
		  calendar.setTime(new Date());
		  int year = calendar.get(Calendar.YEAR);

		  Map params = new HashMap();
		 
		 String  salesYear = request.getParameter("salesYear");
		  if(StringUtils.isNotBlank(salesYear)){
			  params.put("x_salelog_year", new Integer(salesYear));
			  params.put("query_x_salelog_year", new Integer(salesYear));
			  year =  Integer.parseInt(salesYear);
		  }else{
			  params.put("x_salelog_year", new Integer(year));
			  params.put("query_x_salelog_year", new Integer(year));
		  }

        ctx.setQueryParams(params);

        Map dataMap = new HashMap();
		java.util.List rows = null;
		Map userMap = null;
 		ReportService reportService = null;
		try{
 			  reportService = (ReportService)ContextFactory.getBean("reportService");
			  userMap = IntegrationFactory.getUserMap();
              rows = reportService.getYearCompanySaleLogs(ctx);
			  if(rows != null && rows.size()>0){
                 Iterator iterator = rows.iterator();
	             while(iterator.hasNext()){
		            SaleLog model = (SaleLog) iterator.next();
					SaleLog x = (SaleLog) dataMap.get(model.getCompanyId());
                    if( x == null){
						x = new SaleLog();
					}
					x.setCompanyId(model.getCompanyId());
					x.setCompanyName(model.getCompanyName());
					x.setHours(x.getHours() + model.getHours());
					x.setScore(x.getScore() + model.getScore());
                    dataMap.put(x.getCompanyId(), x);
				 }
			  }
		} catch(Exception ex){
            ex.printStackTrace();
	    }

		Collection c = dataMap.values();
        rows = new ArrayList();
		rows.addAll(c);
		Collections.sort(rows);
%>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/pages/styles/styles.css" />
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/scripts/ext/resources/css/ext-all.css" />
<center><br>
<br>
<span class="subject"> <img
	src="<%=request.getContextPath()%>/pages/images/title.gif" alt="公司年度得分">
公司年度得分 </span> <br>
<br>
<table align="center" class="x-table-border" cellspacing="1"
	cellpadding="1" width="80%">
	<tr class="x-title" height="22">
		<td align="center" width="40%">公司</td>
		<td align="center" width="10%">用时</td>
		<td align="center" width="10%">得分</td>
		<td align="right">&nbsp;</td>
	</tr>
	<%if( rows != null){
	 Iterator iterator = rows.iterator();
	 while(iterator.hasNext()){
		 SaleLog model = (SaleLog)iterator.next();
	 %>
	<tr height="22" onmouseover="this.className='x-row-over';"
		onmouseout="this.className='x-row-out';" class="x-content">
		<td align="left" width="40%"><a
			href="<%=request.getContextPath()%>/crm/company.do?method=edit&companyId=<%=model.getCompanyId()%>"
			target="_blank"> <%=model.getCompanyName()%> </a></td>
		<td align="right" width="10%"><a
			href="<%=request.getContextPath()%>/crm/saleLog.do?method=list&query_x_salelog_companyId=<%=model.getCompanyId()%>&query_x_salelog_year=<%=year%>"
			target="_blank"> <%=model.getHours()%>&nbsp; </a></td>
		<td align="right" width="10%"><a
			href="<%=request.getContextPath()%>/crm/saleLog.do?method=list&query_x_salelog_companyId=<%=model.getCompanyId()%>&query_x_salelog_year=<%=year%>"
			target="_blank"> <%=model.getScore()%>&nbsp; </a></td>
		<td align="right">&nbsp;</td>
	</tr>
	<%}
}%>
</table>
<br>
</center>